package com.yzz.hzraisedust.hzraseidust.Login;

import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;

public class User {
	private String mId;
	private String mPwd;
	private static final String masterPassword = "FORYOU";
	private static final String JSON_ID = "user_id";
	private static final String JSON_PWD = "user_pwd";
	private static final String TAG = "User";

	private static final String JSON_SELECED = "currentUser";

	private boolean mSelect;
	public User(String id, String pwd) {
		this.mId = id;
		this.mPwd = pwd;
		mSelect = false;
	}

	public User(JSONObject json) throws Exception {
		if (json.has(JSON_ID)) {
			String id = json.getString(JSON_ID);
			String pwd = json.getString(JSON_PWD);
			mSelect = json.getBoolean(JSON_SELECED);
			mId = AESUtils.decrypt(masterPassword, id);
			mPwd = AESUtils.decrypt(masterPassword, pwd);
		}
	}

	public JSONObject toJSON() throws Exception {

		String id = AESUtils.encrypt(masterPassword, mId);
		String pwd = AESUtils.encrypt(masterPassword, mPwd);
		Log.i(TAG, "用户名密码:" + id + "  " + pwd);
		JSONObject json = new JSONObject();
		try {
			json.put(JSON_ID, id);
			json.put(JSON_PWD, pwd);
			json.put(JSON_SELECED,mSelect);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json;
	}

	public String getId() {
		return mId;
	}

	public String getPwd() {
		return mPwd;
	}

	public boolean isSelect() {
		return mSelect;
	}

	public void setSelect(boolean mSelect) {
		this.mSelect = mSelect;
	}
}
